package com.konsung.ksdc.manager.addr;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.AddrBaseBean;
import com.konsung.ksdc.config.MyApplication;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DistrictCountyAdapter extends BaseAdapter {


    private List<AddrBaseBean> mDatas = new ArrayList<>();
    private Activity activity;
    private String cityName;

    /**
     *
     * @param activity 类
     * @param datas 数据
     * @param cityName 城市名称
     */
    public DistrictCountyAdapter(Activity activity, List<AddrBaseBean> datas, String cityName) {
        mDatas = datas;
        this.activity = activity;
        this.cityName = cityName;
    }


    @Override
    public int getCount() {
        if (mDatas != null) {
            return mDatas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final AddrBaseBean bean = mDatas.get(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout.item_listview_area, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String countyName = bean.getAreaName();

        holder.tvCounty.setText(countyName);

        return convertView;
    }

    /**
     * n内部类
     */
    static class ViewHolder {
        @Bind(R.id.tv_area_name)
        TextView tvCounty;
    }
}
